home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_10.lha / 6_10 / 6_10tst.c < prev    next >
Text File  |  1993-08-08  |  2KB  |  128 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6. include <values.h>
  7.  
  8. include "lint.h"
  9.  
  10. nsigned long iarray[] =
  11.    {
  12.    0,
  13.    1,
  14. /    2,
  15. /    3,
  16. /    4,
  17. /    5,
  18. /    6,
  19. /    17,
  20. /    1234,
  21. /    0x1234,
  22. /    12345,
  23.    0x12345,
  24. /    12345678,
  25.    0x12345678,
  26.    MAXINT,
  27.    0xFFFFFFFF
  28.    };
  29.  
  30. onst int sziarray = sizeof(iarray)/sizeof(iarray[0]);
  31.  
  32. INT Parray[sziarray*sziarray], Narray[sziarray*sziarray];
  33. nt szarray = 0;
  34.  
  35. oid init()
  36.  
  37.    for (int i = 0; i < sziarray; i++)
  38. for (int j = 0; j < sziarray; j++)
  39.     Parray[szarray++] = LINT(iarray[i], iarray[j]);
  40.  
  41.    for (i = 0; i < szarray; i++)
  42. Narray[i] = -Parray[i];
  43.  
  44.  
  45. oid testdiv(LINT *A, LINT *B)
  46.  
  47.    for (int i = 0; i < szarray; i++)
  48. for (int j = 1; j < szarray; j++)
  49.     {
  50.     LINT quot, rem;
  51.     dodivmod(A[i], B[j], quot, rem);
  52.     cout << A[i] << " / " << B[j] << " = " << quot << "\n";
  53.     cout << A[i] << " % " << B[j] << " = " << rem << "\n";
  54.     }
  55.  
  56.  
  57. oid testmul(LINT *A, LINT *B)
  58.  
  59.    for (int i = 0; i < szarray; i++)
  60. for (int j = 0; j < szarray; j++)
  61.     {
  62.     LINT prod = A[i] * B[j];
  63.     cout << A[i] << " * " << B[j] << " = " << prod << "\n";
  64.     }
  65.  
  66.  
  67. oid testadd(LINT *A, LINT *B)
  68.  
  69.    for (int i = 0; i < szarray; i++)
  70. for (int j = 0; j < szarray; j++)
  71.     {
  72.     LINT sum = A[i] + B[j];
  73.     cout << A[i] << " + " << B[j] << " = " << sum << "\n";
  74.     }
  75.  
  76.  
  77. oid testsub(LINT *A, LINT *B)
  78.  
  79.    for (int i = 0; i < szarray; i++)
  80. for (int j = 0; j < szarray; j++)
  81.     {
  82.     LINT diff = A[i] - B[j];
  83.     cout << A[i] << " - " << B[j] << " = " << diff << "\n";
  84.     }
  85.  
  86.  
  87. oid testneg(LINT *A)
  88.  
  89.    for (int i = 0; i < szarray; i++)
  90. {
  91. LINT neg = -A[i];
  92. cout << " - " << A[i] << " = " << neg << "\n";
  93. }
  94.  
  95.  
  96. oid testpos(LINT *A)
  97.  
  98.    for (int i = 0; i < szarray; i++)
  99. {
  100. LINT pos = +A[i];
  101. cout << " 0 + " << A[i] << " = " << pos << "\n";
  102. }
  103.  
  104.  
  105. oid testsuite(LINT *A, LINT *B)
  106.  
  107.    testadd(A, B);
  108.    testsub(A, B);
  109.    testmul(A, B);
  110.    testdiv(A, B);
  111.    testneg(A);
  112.    testpos(A);
  113.  
  114.  
  115. ain(int, char **)
  116.  
  117.    init();
  118. /    for (int i = 0; i < szarray; i++)
  119. /    cerr << "Parray[" << i << "]=" << Parray[i] << "\n";
  120. /    for (i = 0; i < szarray; i++)
  121. /    cerr << "Narray[" << i << "]=" << Narray[i] << "\n";
  122.    testsuite(Parray, Parray);
  123. /    testsuite(Parray, Narray);
  124. /    testsuite(Narray, Parray);
  125. /    testsuite(Narray, Narray);
  126.    return 0;
  127.  
  128.